
package languageacquisition;

import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.GroupLayout.Group;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Point;

public class Visualization2 extends JFrame {

	static DBCreation database;
	private static int desLength;
	private static int OA_number;
	private static int PA_number;
	
	private JFrame visual = new JFrame();
	private JPanel upPanel = new JPanel();
	private JPanel downPanel = new JPanel();
	private JPanel leftPanel = new JPanel();
	private JPanel rightPanel = new JPanel();
	
	
	
	private ArrayList<JLabel> PA_labels = new ArrayList<JLabel>();
	private static ArrayList<JLabel> PA_lArrows = new ArrayList<JLabel>();
	private static ArrayList<JLabel> PA_rArrows = new ArrayList<JLabel>();
	
	private JLabel NA_label = new JLabel();
	private JLabel NA_lArrow = new JLabel();
	private JLabel NA_rArrow = new JLabel();
	
	private ArrayList<JLabel> OA_labels = new ArrayList<JLabel>();
	private static ArrayList<JPanel> des_labels = new ArrayList<JPanel>();


	public Visualization2()
	{
		visual = this;
		setTitle("Visualization");
		setSize((100*PA_number + 130), (130 + 30*OA_number));
		Container contentPane = getContentPane();
		
		upPanel.setBorder(BorderFactory.createEtchedBorder());
		upPanel.setPreferredSize(new Dimension((100*PA_number + 110), 100));
		downPanel.setBorder(BorderFactory.createEtchedBorder());
		downPanel.setPreferredSize(new Dimension((100*PA_number + 110), (30*OA_number + 10)));
		leftPanel.setBorder(BorderFactory.createEtchedBorder());
		leftPanel.setPreferredSize(new Dimension((100*PA_number), 100));
		leftPanel.setLayout(new GridLayout(1, PA_number));
		rightPanel.setBorder(BorderFactory.createEtchedBorder());
		rightPanel.setPreferredSize(new Dimension(100, 100));
		rightPanel.setLocation(new Point(700, 0));
		
		contentPane.add(upPanel, BorderLayout.NORTH);
		contentPane.add(downPanel, BorderLayout.CENTER);
		upPanel.add(leftPanel, BorderLayout.WEST);
		upPanel.add(rightPanel, BorderLayout.EAST);
		
		//----- LEFT PANEL -----
		
		for (int i = 1; i <= PA_number; i++)
		{
			JPanel temp = new JPanel();
			temp.setLayout(new BorderLayout());	
			leftPanel.add(temp);
			
			JLabel lab = new JLabel();
			lab.setText("PA " + i);
			PA_labels.add(lab);
			temp.add(lab, BorderLayout.WEST);
			temp.setBorder(BorderFactory.createEtchedBorder());
			
			JPanel temp2 = new JPanel();
			temp2.setLayout(new GridLayout(2,1));
			temp.add(temp2, BorderLayout.EAST);
			
			JLabel lArrow = new JLabel();
			lArrow.setIcon(new javax.swing.ImageIcon("bin\\languageacquisition\\Images\\ArrowL.PNG")); // NOI18N
			//lArrow.setVisible(false);
			PA_lArrows.add(lArrow);
			temp2.add(lArrow);
			
			
			JLabel rArrow = new JLabel();
			rArrow.setIcon(new javax.swing.ImageIcon("bin\\languageacquisition\\Images\\ArrowR.PNG")); // NOI18N
			//rArrow.setVisible(false);
			PA_rArrows.add(rArrow);
			temp2.add(rArrow);
			//rArrow.setVerticalAlignment(i*10);
			
		}

		//----- RIGHT PANEL -----
		
		{
			NA_label.setText("NA");
			rightPanel.add(NA_label, BorderLayout.WEST);
		
			JPanel temp2 = new JPanel();
			temp2.setLayout(new GridLayout(2,1));
			rightPanel.add(temp2, BorderLayout.EAST);
			
			NA_lArrow.setIcon(new javax.swing.ImageIcon("bin\\languageacquisition\\Images\\ArrowL.PNG")); // NOI18N
			//lArrow.setVisible(false);
			temp2.add(NA_lArrow);
		
			NA_rArrow.setIcon(new javax.swing.ImageIcon("bin\\languageacquisition\\Images\\ArrowR.PNG")); // NOI18N
			//rArrow.setVisible(false);
			temp2.add(NA_rArrow);
			
		}
		
		//----- DOWN PANEL -----
		
		
		downPanel.setLayout(new GridLayout(OA_number,desLength+1));
		
		for (int j = 1; j <= OA_number; j++)
		{
			JLabel lab = new JLabel();
			lab.setText("OA " + j);
			OA_labels.add(lab);
			downPanel.add(lab);
			
			for (int k = 1; k <= desLength; k++)
			{
				JPanel lab2 = new JPanel();
				lab2.setBackground(new java.awt.Color(0, 153, 51));
				lab2.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

		        javax.swing.GroupLayout O28Layout = new javax.swing.GroupLayout(lab2);
		        lab2.setLayout(O28Layout);
		        O28Layout.setHorizontalGroup(
		            O28Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		            .addGap(0, 9, Short.MAX_VALUE)
		        );
		        O28Layout.setVerticalGroup(
		            O28Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
		            .addGap(0, 34, Short.MAX_VALUE)
		        );
				des_labels.add(lab2);
				downPanel.add(lab2);
				
			}
		
		}
	}
	public static void knoledgeUpdate(int id)
	{
	  	PA_lArrows.get(id).setVisible(true);
	   	for (int i=0; i<500000000; i++){}
	   	PA_lArrows.get(id).setVisible(false);
	}
	
	public static void messageSend(int id)
    {
		PA_rArrows.get(id).setVisible(true);
	   	for (int i=0; i<500000000; i++){}
	   	PA_rArrows.get(id).setVisible(false);
    }
	
	public static void updateDescription(int id, int[] arr)
    {
		for (int m = 0; m < desLength; m++)
		{
			if (arr[m] == 1) des_labels.get(desLength*(id-48)+m).setBackground(new java.awt.Color(0, 153, 51));
			else des_labels.get(desLength*(id-48)+m).setBackground(new java.awt.Color(236,233,216));
		}
    }
		
	
	public static void Visualization2GUI(int desLen, int OA_num, int PA_num) {
		desLength = desLen;
		OA_number = OA_num;
		PA_number = PA_num;
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new Visualization2().setVisible(true);
				database = new DBCreation("localhost","root","pass");
            	database.createTables(desLength);
			}
		});
	}
	 
	

}
